// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>
#include <turbo/log/logging.h>

namespace cantor::unresolved {
    class UnresolvedDispatchExpr;

    class UnresolvedIndirection : public UnresolvedVisitor<UnresolvedIndirection> {
    public:
        static constexpr const cantor::pb::ast::ExprNodeType TYPE = cantor::pb::ast::ExprNodeType::ENT_INDIRECTION;

        UnresolvedIndirection(const cantor::pb::ast::Indirection &node) : instance(node) {
        }

        ~UnresolvedIndirection() override = default;

        const pb::Location &location_impl() const {
            return instance.location();
        }

        const pb::Status &error_status_impl() const {
            return instance.status();
        }

        cantor::pb::ast::IndirectionType type() const {
            return instance.type();
        }

        bool is_index() const {
            return type() == cantor::pb::ast::IndirectionType::IND_INDEX;
        }

        UnresolvedDispatchExpr index_expr() const;

        bool has_slice_low() const {
            return instance.slice().has_low();
        }
        bool has_slice_high() const {
            return instance.slice().has_high();
        }
        bool has_slice_step() const {
            return instance.slice().has_step();
        }
        UnresolvedDispatchExpr slice_low() const;

        UnresolvedDispatchExpr slice_high() const;

        UnresolvedDispatchExpr slice_step() const;

        bool is_slice() const {
            return type() == cantor::pb::ast::IndirectionType::IND_SLICE;
        }

        UnresolvedDispatchExpr count() const;

        UnresolvedDispatchExpr offset() const;

        const cantor::pb::ast::Indirection &instance;
    };
} // namespace cantor::unresolved
